<?php
/**
 * Created by PhpStorm.
 * User: mikol
 * Date: 2018/8/1 0001
 * Time: 17:51
 */

namespace app\api\controller;


use think\Request;

class Index
{
    public function index()
    {
        $data = Request::instance()->param();
        #file_put_contents("./test.log",json_encode($data));
        $token= 'cscscs';
        $tmpArr = array($data['nonce'],$token,$data['timestamp']);
        sort($tmpArr,SORT_STRING);

        // 2）将三个参数字符串拼接成一个字符串进行sha1加密
        $str = implode($tmpArr);
        $sign = sha1($str);

        // 3）开发者获得加密后的字符串可与signature对比，标识该请求来源于微信
        if ($sign == $data['signature']) {
            return $data['echostr'];
        }else{
            return $data['echostr'];
        }
    }


}